﻿@model Fcom.VNInsurance.Web.Models.NewsCategory
@{
    ViewBag.Title = "Quản lý bài viết";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
}
 <link rel="stylesheet" href="@Url.Content("~/Content/jqwidgets/styles/jqx.base.css")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcore.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdata.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxbuttons.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxscrollbar.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxmenu.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcheckbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxlistbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdropdownlist.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.sort.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.pager.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.selection.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.edit.js")"></script> 
<script type="text/javascript">
        $(document).ready(function () {
           
            var url = "@Url.Action("GetJsonCatNews", "News", new { CatID=Model.ID})";
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'NewID', type: 'int' },
                    { name: 'LangID', type: 'string' },
                    { name: 'Title', type: 'float' },
                    { name: 'Translated', type: 'bool' },
                    { name: 'PostDate', type: 'datetime' },
                    { name: 'CatName', type: 'string' }
                ],
                id: 'NewID',
                url: url
            };
           

            var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data, status, xhr) { },
                loadComplete: function (data) { },
                loadError: function (xhr, status, error) { }
            });
         
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 940,
                source: dataAdapter,
                pageable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                editable: true,
                selectionmode: 'multiplecellsadvanced',
                columns: [
                  { text: 'ID', datafield: 'NewID', width: 30 },
                  
                  { text: 'Tiêu đề', datafield: 'Title', width: 440 },
                   { text: 'Phân Loại', datafield: 'CatName', width: 100 },
                  { text: 'Ngày viết', datafield: 'PostDate', width: 100 },
                  { text: 'Đã Dịch', columntype: 'checkbox', datafield: 'Translated', width: 70 },
                  {
                     text: 'Chỉnh sửa', datafield: 'Edit', columntype: 'button', width: 100, cellsrenderer: function () {
                         return "Edit";
                     }, buttonclick: function (editrow) {

                         var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                        window.location = "@Url.Action("EditNews","News")/" + dataRecord.NewID;
                     }
                  },
                   {
                       text: 'Xóa', datafield: 'Delete', columntype: 'button', width: 100, cellsrenderer: function () {
                           return "Delete";
                       }, buttonclick: function (editrow) {

                           var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                           var rr = confirm("Bạn có muốn xóa bài viết \"" + dataRecord.Title + "\" ?");
                           if (rr) {
                               $.ajax({
                                   type: "post",
                                   url: "@Url.Action("DeleteNewsByID","News")",
                                  data: { NewsID: dataRecord.NewID },
                                  datatype: "json",
                                  success: function (rvdata) {
                                      if (rvdata.success) {
                                          $("#jqxgrid").jqxGrid({ source: dataAdapter });
                                      }
                                  }

                              });
                          }//end rr

                      }
                   }
                ]                
            });
        });
    </script>
<div class="container" style="padding:10px;">
    <fieldset>
                 <legend >Quản lý bài viết <span style="color:#000">@Model.Name</span></legend>
   </fieldset>
   <div id="jqxgrid" class="container">

   </div>
</div>
